package com.kehutong.payfees.admin;

import com.kehutong.common.util.Token;
import com.kehutong.payfees.entity.receipt.ReceiptTemplate;
import com.kehutong.payfees.service.receipt.ReceiptTempServiceImpl;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

/**
 * @program: kht
 * @description: 模板管理
 * @author: joneron
 * @create: 2021/5/29
 **/
@MvcAction
@ReqMapping("/admin/crm/charge/receipt/temp")
public class ReceiptTempController {

    @Inject
    ReceiptTempServiceImpl receiptService;

    @ReqMapping("/page")
    @HasPermission("crm:charge:receipt:temp:view")
    public Object page(JSONObject jsonObject) {
        return receiptService.findPage(jsonObject);
    }

    @ReqMapping("/list")
    @HasPermission("crm:charge:receipt:temp:view")
    public Object list(JSONObject jsonObject) {
        return receiptService.findList(jsonObject);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:charge:receipt:temp:edit")
    @ReqMapping("/save")
    public Object save(ReceiptTemplate entity, Token token) {
        entity.setUpdateName(token.getUsername());
        return receiptService.save(entity);
    }

    @Bean(copy=true)
    @HasPermission("crm:charge:receipt:temp:edit")
    @ReqMapping("/update")
    public Object update(ReceiptTemplate entity) {

        return receiptService.update(entity);
    }

    @HasPermission("crm:charge:receipt:temp:edit")
    @ReqMapping("/delete")
    public Object delete(ReceiptTemplate entity) {

        return receiptService.deleteById(entity.getId());
    }

    @ReqMapping("/setStatus")
    @HasPermission("crm:charge:receipt:temp:edit")
    public Object setStatus(ReceiptTemplate entity) {
        entity.setStatus(!entity.isStatus());
        receiptService.update(entity);
        return Result.success();
    }

    @ReqMapping("/get")
    public Object get(ReceiptTemplate entity) {

        return Result.success(entity);
    }
}
